#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <string.h>

int main(int argc, char** argv){
    if(argc == 1){
        fprintf(stderr, "Usage : %s *.c args", argv[0]);
    }

    pid_t pid;
    if((pid = fork()) < -1){
        perror("fork()");
        exit(1);
    }
    else if(pid == 0){
        execl("/usr/bin/vim", "/usr/bin/vim", argv[1], NULL);
        return 0;
    }

    wait(NULL);

    char buf[128];
    strncpy(buf, argv[1], strlen(argv[1]) - 2); 
    buf[strlen(argv[1]) - 2] = '\0';

    if((pid = fork()) < -1){
        perror("fork()");
        exit(1);
    }
    else if(pid == 0){    
        execl("/usr/bin/gcc", "gcc", argv[1], "-o", buf, NULL);
        return 0;
    }
    wait(NULL);



    printf("i will hello\n");
    char buffer[1024];
    buffer[0] = '.';
    buffer[1] = '/';
    buffer[2] = '\0';
    char* buffer1 = argv[2];
    char* args[3];
    args[0] = buf;
    args[1] = buffer1;
    args[2] = NULL;
    strcat(buffer, buf);   
    execv(buffer, args);


    return 0;
}